home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / expand.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  78 lines

  1. ; $Id: expand.pro,v 1.2 1996/12/17 23:44:16 lubos Exp $
  2.  
  3. ;+
  4. ; NAME:
  5. ;    EXPAND
  6. ; PURPOSE:
  7. ;    Array magnification  (CONGRIDI like except that this really works!)
  8. ; CATEGORY:
  9. ;    Z4 - IMAGE PROCESSING
  10. ; CALLING SEQUENCE:
  11. ;    EXPAND,A,NX,NY,RESULT [,MAXVAL=MAXVAL,FILLVAL=FILLVAL]
  12. ; INPUTS:
  13. ;    A    Array to be magnified
  14. ;    NX    Desired size of X Dimension
  15. ;    NY    Desired size of Y Dimension
  16. ; Keywords:
  17. ;    MAXVAL    Largest good value. Elements greater than this are ignored
  18. ;    FILLVAL    Value to use when elements larger than MAXVAL are encountered.
  19. ;        Defaults to -1.
  20. ; OUTPUTS:
  21. ;    RESULT    Magnified Floating point image of A array (NX by NY)
  22. ; COMMON BLOCKS:
  23. ;    NONE
  24. ; SIDE EFFECTS:
  25. ;    NONE
  26. ; RESTRICTIONS:
  27. ;    A must be two Dimensional
  28. ; PROCEDURE:
  29. ;    Bilinear interpolation.
  30. ;    Not really fast if you have to swap memory (eg. NX*NY is a big number).
  31. ;    OK Postscript users don't forget that postscript pixels are scaleable!
  32. ; MODIFICATION HISTORY:
  33. ;    Aug 15, 1989    J. M. Zawodny, NASA/LaRC, MS 475, Hampton VA, 23665.
  34. ;    Aug 26, 1992    JMZ, Added maxval and fillval keywords.
  35. ;    Sep 30, 1992    DMS, RSI, Rewrote to use INTERPOLATE function.
  36. ; Please send suggestions and bugreports to zawodny@arbd0.larc.nasa.gov
  37. ;-
  38. pro EXPAND,a,nx,ny,result,maxval=maxval,fillval=fillval
  39.  
  40.     s=size(a)
  41.     if(s[0] ne 2) then begin
  42.         print,'EXPAND: *** array must be 2-Dimensional ***'
  43.         retall  ; This will completely terminate the MAIN program!!!
  44.     endif
  45.  
  46.    ; Get dimensions of the input array
  47.     ix = s[1]
  48.     iy = s[2]
  49.  
  50.    ; Calculate the new grid in terms of the old grid
  51.     ux = findgen(nx) * ((ix-1.) / (nx-1.))
  52.     uy = findgen(ny) * ((iy-1.)/ (ny-1.))
  53.  
  54.    ;  Interpolate the result
  55.     result = INTERPOLATE(a, ux, uy, /GRID)
  56.  
  57.    ; Are we to look for and ignore bad data?
  58.     if (n_elements(maxval) gt 0) then begin
  59.             ;Find where missing points end up
  60.         bad_pts = INTERPOLATE(float(a gt maxval), ux, uy, /GRID)
  61.             ;The only Non-zero points are those resulting from
  62.             ;bad points.  Get their subscripts in the result
  63.         bad_subs = WHERE(bad_pts, count)    ;Any bad pnts
  64.         if count ge n_elements(result) then goto, out    ;All bad
  65.         if n_elements(fillval) le 0 then fillval = -1
  66.             ;Substitute missing value
  67.         if count gt 0 then result[bad_subs] = fillval
  68.     endif
  69.  
  70. ; Done
  71. return
  72. OUT:    ; If we had a problem
  73. print,'Entire input array is greater than MAXVAL, ('+strtrim(maxval,2)+')'
  74. return
  75. end
  76.  
  77.  
  78.